#!/bin/sh
starttime=
dosedxstart=
dosedystart=
dosedbasex=
dosedbasey=
dosedysetp1=
dosedentbbx=
dosedentbby=

sectionname=$(echo $0 | cut -d '/' -f 3 | cut -d '_' -f 1 | sed 's/^ADBRUN//')
adbclient=$(uci get adbrun.$sectionname.adbiplist)
rm /tmp/adb_ADBRUN${sectionname}_.sh

function gotobbfm() {
	adb -s ${adbclient}:5555 shell am force-stop com.taobao.taobao
	sleep 5
	adb -s ${adbclient}:5555 shell am start -n com.taobao.taobao/com.taobao.tao.TBMainActivity
	sleep 18
	adb -s ${adbclient}:5555 shell input tap $entbbx $entbby
	sleep 10
}

gotobbfm
adb -s ${adbclient}:5555 shell input keyevent 4
sleep 5
gotobbfm

screensize=$(adb -s ${adbclient}:5555 shell wm size | cut -d ':' -f 2 | sed -e "s/ //g;s/\n//g;s/\r//g")
ltimes=0
while [ $ltimes -lt 3 ]
do
if [ ${screensize} == "720x1280" ];then
	adb -s ${adbclient}:5555 shell input tap $(expr $basex - 260) $(expr $basey + $ysetp1 \* 5)
else
	adb -s ${adbclient}:5555 shell input tap $(expr $basex - 260) $(expr $basey + $ysetp1 \* 7)
fi
	sleep 2
	ltimes=$(expr $ltimes + 1)
done
adb -s ${adbclient}:5555 shell input keyevent 4
sleep 5
gotobbfm

if [ ${screensize} == "720x1280" ];then
	adb -s ${adbclient}:5555 shell input tap $(expr $basex \* 5 / 6) $(expr $basey + $ysetp1 \* 5)
else
	adb -s ${adbclient}:5555 shell input tap $(expr $basex \* 5 / 6) $(expr $basey + $ysetp1 \* 7)
fi
sleep 5

adb -s ${adbclient}:5555 shell input tap $basex $basey
sleep 5

ltimes=0
while [ $ltimes -lt 4 ]
do
	adb -s ${adbclient}:5555 shell input tap $basex $(expr $basey + $ysetp1 \* 2)
	sleep 3
	adb -s ${adbclient}:5555 shell input swipe $xstart $ystart $xstart $(expr $ystart - 600)
	sleep 25
	adb -s ${adbclient}:5555 shell input keyevent 4
	sleep 5
	ltimes=$(expr $ltimes + 1)
done

adb -s ${adbclient}:5555 shell input swipe $xstart $ystart $xstart $(expr $ystart - 600)
sleep 5

if [ ${screensize} == "720x1280" ];then
	adb -s ${adbclient}:5555 shell input tap $basex $(expr $basey + $ysetp1 \* 4)
else
	adb -s ${adbclient}:5555 shell input tap $basex $(expr $basey + $ysetp1 \* 6)
fi
sleep 5

if [ ${screensize} == "720x1280" ];then
	echo "skip"
else
	adb -s ${adbclient}:5555 shell input tap $basex $(expr $basey + $ysetp1)
	sleep 3
	adb -s ${adbclient}:5555 shell input swipe $xstart $ystart $xstart $(expr $ystart - 600)
	sleep 25
	adb -s ${adbclient}:5555 shell input keyevent 4
	sleep 5
fi

if [ ${screensize} == "720x1280" ];then
	adb -s ${adbclient}:5555 shell input tap $basex $(expr $basey + $ysetp1 \* 2)
else
	adb -s ${adbclient}:5555 shell input tap $basex $(expr $basey + $ysetp1 \* 3)
fi
sleep 37
adb -s ${adbclient}:5555 shell input keyevent 4
sleep 5

adb -s ${adbclient}:5555 shell input tap $basex $(expr $basey + $ysetp1)
sleep 3
adb -s ${adbclient}:5555 shell input swipe $xstart $ystart $xstart $(expr $ystart - 600)
sleep 25
adb -s ${adbclient}:5555 shell input keyevent 4
sleep 5

if [ ${screensize} == "720x1280" ];then
	adb -s ${adbclient}:5555 shell input tap $basex $(expr $basey + $ysetp1 \* 3)
else
	adb -s ${adbclient}:5555 shell input tap $basex $(expr $basey + $ysetp1 \* 5)
fi
sleep 25
adb -s ${adbclient}:5555 shell input keyevent 4
sleep 2
adb -s ${adbclient}:5555 shell input keyevent 4
sleep 5

adb -s ${adbclient}:5555 shell am force-stop com.taobao.taobao
